import { assertEquals } from "asserts";

import { ArrayToListNode } from "../reverse-linked-list/ArrayToListNode.ts";
import reverseKGroup from "./index.ts";

Deno.test("reverse-nodes-in-k-group", () => {
    const inputs: [number[], number][] = [[[1, 2, 3, 4, 5], 2], [[
        1,
        2,
        3,
        4,
        5,
    ], 3], [[
        1,
        2,
        3,
        4,
        5,
        1,
        2,
        3,
        4,
        5,
        1,
        2,
        3,
        4,
        5,
        1,
        2,
        3,
        4,
        5,
        1,
        2,
        3,
        4,
        5,
    ], 4]];
    assertEquals(
        inputs.map(([a, b]) => reverseKGroup(ArrayToListNode(a), b)),
        [[2, 1, 4, 3, 5], [3, 2, 1, 4, 5], [
            4,
            3,
            2,
            1,
            3,
            2,
            1,
            5,
            2,
            1,
            5,
            4,
            1,
            5,
            4,
            3,
            5,
            4,
            3,
            2,
            4,
            3,
            2,
            1,
            5,
        ]].map(ArrayToListNode),
    );
});
